package cn.bmyi.webautotest.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 读取配置文件
 * 
 * @author 毛建杰
 *
 */
public class Config
{
	private static Properties config;

	/**
	 * 打开配置文件
	 * 
	 * @param inputStream
	 *            inputStream
	 */
	public static void open(InputStream inputStream)
	{
		Properties properties = new Properties();
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
		try
		{
			properties.load(bufferedReader);
		}
		catch (IOException e)
		{
			Logger.error(e.getMessage());
		}
		config = properties;
	}

	/**
	 * 关闭配置文件
	 */
	public static void close()
	{
		if (config != null)
		{
			config = null;
		}
	}

	/**
	 * 获取配置文件键值
	 * 
	 * @param key
	 *            键
	 * @return 值
	 */
	public static String getProperty(String key)
	{
		return config.getProperty(key);
	}
}
